package com.gzc.just.play.last.war.centralserver.match.model;



import com.gzc.just.play.last.war.centralserver.battle.model.BattleRoom;

import com.gzc.just.play.last.war.centralserver.match.model.MatchRequest.MatchStatus;



import java.util.ArrayList;

import java.util.List;



public class MatchResult {

    private boolean success;

    private long matchId;

    private String message;

    private List<MatchRequest> matchedRequests;

    private BattleRoom battleRoom;

    

    private MatchResult() {

    }

    

    public static MatchResult success(List<MatchRequest> matchedRequests, BattleRoom battleRoom) {

        MatchResult result = new MatchResult();

        result.success = true;

        result.matchedRequests = new ArrayList<>(matchedRequests);

        result.battleRoom = battleRoom;

        result.message = "Match successful";

        

        if (!matchedRequests.isEmpty()) {

            result.matchId = matchedRequests.get(0).getMatchId();

        }

        

        return result;

    }

    

    public static MatchResult cancelled(long matchId) {

        MatchResult result = new MatchResult();

        result.success = false;

        result.matchId = matchId;

        result.message = "Match cancelled";

        

        return result;

    }

    

    public static MatchResult timeout(long matchId) {

        MatchResult result = new MatchResult();

        result.success = false;

        result.matchId = matchId;

        result.message = "Match timeout";

        

        return result;

    }

    

    public static MatchResult failure(long matchId, String message) {

        MatchResult result = new MatchResult();

        result.success = false;

        result.matchId = matchId;

        result.message = message;

        

        return result;

    }

    

    // Getters and Setters

    public boolean isSuccess() {

        return success;

    }

    

    public void setSuccess(boolean success) {

        this.success = success;

    }

    

    public long getMatchId() {

        return matchId;

    }

    

    public void setMatchId(long matchId) {

        this.matchId = matchId;

    }

    

    public String getMessage() {

        return message;

    }

    

    public void setMessage(String message) {

        this.message = message;

    }

    

    public List<MatchRequest> getMatchedRequests() {

        return matchedRequests;

    }

    

    public void setMatchedRequests(List<MatchRequest> matchedRequests) {

        this.matchedRequests = matchedRequests;

    }

    

    public BattleRoom getBattleRoom() {

        return battleRoom;

    }

    

    public void setBattleRoom(BattleRoom battleRoom) {

        this.battleRoom = battleRoom;

    }

    

    public List<Long> getAllUserIds() {

        List<Long> userIds = new ArrayList<>();

        

        if (matchedRequests != null) {

            for (MatchRequest request : matchedRequests) {

                if (request.getUserId() > 0) {

                    userIds.add(request.getUserId());

                } else if (request.getTeamId() > 0) {

                }

            }

        }

        

        return userIds;

    }

    

    @Override

    public String toString() {

        return "MatchResult{" +

                "success=" + success +

                ", matchId=" + matchId +

                ", message='" + message + '\'' +

                ", battleRoom=" + (battleRoom != null ? battleRoom.getRoomId() : "null") +

                '}';

    }

}

